home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / FCVT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  862 b   |  26 lines

  1. /* fcvt.c, from p.175 of Turbo C Bible  */
  2. /* Converts a double-precision floating-point value into a string without
  3.     an embedded decimal point and rounds the value to a specified number
  4.     of digits (the sign of the value and the position of the decimal point
  5.     are returned separately). */
  6. #include <stdio.h>
  7. #include <math.h>
  8. #include <stdlib.h>
  9. main(int argc, char **argv)
  10. {
  11.     int dec, sign, precision = 10;
  12.     double value;
  13.     char  *p_buffer;
  14.     if(argc < 2)
  15.     {
  16.         printf("Usage: %s <value>\n", argv[0]);
  17.     }
  18.     else
  19.     {                             /* Convert the number to internal   */
  20.         value = atof(argv[1]);/*     form.  Then call fcvt.       */
  21.         p_buffer = fcvt(value, precision, &dec, &sign);
  22.         printf("Buffer from fcvt contains: %s\n"
  23.                 "Location of decimal point: %d\n"
  24.         "Sign(0 = pos, 1 = neg)   : %d\n", p_buffer, dec, sign);
  25.     }
  26. }